package com.xjh.him.controller;


import com.xjh.him.annotation.LoginVerify;
import com.xjh.him.dto.friend.FriendDTO;
import com.xjh.him.dto.friend.FriendQueryResultDTO;
import com.xjh.him.service.FriendServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xjh.tool.dto.ResultDTO;
import org.xjh.tool.vo.AjaxResultVO;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/friend")
public class FriendController {

    @Autowired
    private FriendServiceImpl friendService;


    @LoginVerify
    @RequestMapping("/list")
    public AjaxResultVO listFriend() {
        ResultDTO<Map<String, List<FriendDTO>>> resultDTO = friendService.listFriend();
        if (resultDTO.isSuccess()) {
            return AjaxResultVO.getSuccessResult(resultDTO.getResult());
        }
        return AjaxResultVO.getFailureResult(resultDTO.getErrMsg());
    }

    @LoginVerify
    @RequestMapping("/verify")
    public AjaxResultVO verifyFriend(String phone) {
        ResultDTO<FriendQueryResultDTO> resultDTO = friendService.verifyFriend(phone);
        if (resultDTO.isSuccess()) {
            return AjaxResultVO.getSuccessResult(resultDTO.getResult());
        }
        return AjaxResultVO.getFailureResult(resultDTO.getErrMsg());
    }
}
